package com.anrongtec.zcpt.widget;

import android.content.Context;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

/**
 * 作者：liuhui on 2017/2/13 11:02
 * 邮箱：liu594545591@126.com
 * 描述：VerticalSwipeRefreshLayout
 */

public class VerticalSwipeRefreshLayout extends SwipeRefreshLayout {

    private int scaleTouchSlop;
    private float preX;

    public VerticalSwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        //是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。
        scaleTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                preX = ev.getX();
                break;

            case MotionEvent.ACTION_MOVE:
                float moveX = ev.getX();
                float instanceX = Math.abs(moveX - preX);

                // 容差值大概是24，再加上60
                //X方向移动的距离大于下面的值,则不触发下拉
                if(instanceX > scaleTouchSlop + 60){
                    return false;
                }

                break;
        }
        return super.onInterceptTouchEvent(ev);
    }
}
